﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ClaseBase;
using System.Collections.ObjectModel;
namespace Grupo04Playa
{
    /// <summary>
    /// Interaction logic for ListadoDeUsuario.xaml
    /// </summary>
    public partial class ListadoDeUsuario : Window
    {
        string cadena;
      
        public ListadoDeUsuario()
        {
            InitializeComponent();


            cadena = txtFiltro.Text;
            
             
        }
        CollectionView vista;
        ObservableCollection<Usuario> lista;
        CollectionViewSource listafiltrada;

        private void CollectionViewSource_Filter(object sender, FilterEventArgs e )
        {



            if (cadena == null)
            {

            }
            else
            {
                Usuario usuariof = (Usuario)e.Item;


                if (usuariof.Apellido.StartsWith(cadena))
                    e.Accepted = true;
                else
                    e.Accepted = false;


            }

               
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
           
            ObjectDataProvider odp = (ObjectDataProvider)this.Resources["usuarios"];
            lista = odp.Data as ObservableCollection<Usuario>;
            vista = (CollectionView)CollectionViewSource.GetDefaultView(lista);
            listafiltrada = (CollectionViewSource)this.Resources["usuariosOrdenados"];
            
               
        
        }

        private void txtFiltro_TextChanged(object sender, TextChangedEventArgs e)
        {

          


            if (listafiltrada != null)
                cadena = txtFiltro.Text;
                listafiltrada.Filter += new FilterEventHandler(CollectionViewSource_Filter);
            
        }

     

        //private void txtFiltro_KeyDown(object sender, KeyEventArgs e)
        //{

        //    cadena = txtFiltro.Text;
        //}

      

       

       

    }
}
